<?php

namespace App\Http\Controllers\Manager;

use App\Http\Controllers\Controller;
use App\Models\ServerAuth;
use App\Models\ServerEngine;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ServerEngineController extends Controller
{
    public $prefix='manager.serverEngine';

    public function index(){
        return view($this->prefix.'.index');
    }

    public function list(Request $request){
//        $user=Auth::user();
//        $list=$user->serverAuths;
        $list=ServerEngine::where('status','>',0)->with('user');
        if ($request->get('my')=='1'){
            $list=$list->where('user_id',Auth::id());
        }
        $list=$list->get();
        return ['list'=>$list];

    }
    public function getAuthList(Request $request){
        $se=ServerEngine::find($request->get('id'));
        if ($se->user_id !== Auth::id()){
            return 0;
        }
        return ['list'=>$se->serverAuth];
    }
    public function updateEndTime(Request $request){
        $id=$request->get('id');
        $sa=ServerAuth::find($id);
        if ($sa->serverEngine->user->id != Auth::id()){
            return 0;
        }
        $endTime=$request->get('endTime');
        $sa->endTime=$endTime;
        $sa->save();
        return 1;
    }

}
